package cn.change360.newappchildrenenglish.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.change360.newappchildrenenglish.R;
import cn.change360.newappchildrenenglish.mode.Words;

/**
 * Created by Jacky on 2015/10/22.
 */

public class KeyboardAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private List<String> datas;
    private Context context;


    public KeyboardAdapter(Context context, List<String> datas) {
        this.mInflater = LayoutInflater.from(context);
        this.datas = datas;
        this.context = context;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int arg0) {
        return datas.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.adapter_keyboard, null);
            holder.keyboard = (TextView) convertView.findViewById(R.id.keyboard);
            holder.keyimg = (ImageView) convertView.findViewById(R.id.keyimg);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (datas.get(position) == "-1") {
            holder.keyimg.setVisibility(View.VISIBLE);
            holder.keyimg.setImageDrawable(context.getResources().getDrawable(R.drawable.ico_submit));
            //提交按钮
        } else if (datas.get(position) == "-2") {
            holder.keyimg.setVisibility(View.VISIBLE);
            holder.keyimg.setImageDrawable(context.getResources().getDrawable(R.drawable.ico_del));
            //退格按钮
        } else if (datas.get(position) == "-3") {
            holder.keyimg.setVisibility(View.VISIBLE);
            holder.keyimg.setImageDrawable(context.getResources().getDrawable(R.drawable.ico_reading));
            //朗读按钮
        } else if (datas.get(position) == "-4") {
            holder.keyimg.setVisibility(View.VISIBLE);
            holder.keyimg.setImageDrawable(context.getResources().getDrawable(R.drawable.ico_refresh));
            //更换按钮
        } else {
            holder.keyimg.setVisibility(View.GONE);
            holder.keyboard.setText(datas.get(position) + "");
        }
        return convertView;
    }

    public final class ViewHolder {
        public TextView keyboard;
        public ImageView keyimg;
    }
}